package com.zzw.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;

/**
 * created by zzw
 */
public class ReflectTest {

   /* public void func(String[] args) {
        System.out.println((args == null) ? "null" : args.length);
    }*/

    public void func(String key, String[] args) {
        System.out.println((args == null) ? "null" : args.length);
    }

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        ReflectTest obj = new ReflectTest();
       /* Method m = null;
        try {
            m = obj.getClass().getMethod("func", String[].class);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }*/
      /*  m.invoke(obj, new String[1]);  //1
        m.invoke(obj, new Object[]{new String[] {"a", "b"}}); //2
        m.invoke(obj, (Object) new String[] {"a", "b"}); //3*/
       // m.invoke(obj, new String[] {"a"});  //4
       // m.invoke(obj, new String[] {"a", "b"}); //5
        //m.invoke(obj, new Object[]{new String[]{}});  //6
       // m.invoke(obj, new String[]{});

        Method m2 = obj.getClass().getMethod("func", String.class, String[].class);
        m2.invoke(obj, new String(), new String[1]);  //1
       // m2.invoke(obj, new String(), new Object[]{new String[] {"a", "b"}}); //2
        m2.invoke(obj, new String(), (Object) new String[] {"a", "b"}); //3
        m2.invoke(obj, new String(), new String[] {"a"});  //4
        m2.invoke(obj, new String(), new String[] {"a", "b"}); //5
        m2.invoke(obj, new String(), new String[2]);  //6

        m2.invoke(obj, new String(), new String[] {});
    }
}
